import url_configYz from './configYedh.js'

const requestYz = {}
const headers = {}
const PORT1 = '/baseinfo'

requestYz.globalRequest = (url, method, data, power) => {
	return uni.request({
		url: url_configYz + url,
		method,
		data: data,
		dataType: 'json',
		header: headers
	}).then(res => {
		return res
	}).catch(parmas => {
		switch (parmas.code) {
			case 401:
				uni.clearStorageSync()
				break
			default:
				uni.showToast({
					title: parmas.message,
					icon: 'none'
				})
				return Promise.reject()
				break
		}
	})
}
requestYz.post2 = (url, data, power) => {
	let requestUrl
	//console.log(request.baseUrl,'请求地址---------员工端----------------------',urlObject.port)
	if(url_configYz.includes('www')){
		//console.log('正式环境---------------')
		requestUrl = url_configYz + url;
	}else if(url_configYz.includes("132") && process.env.NODE_ENV=='production'){
		//console.log('测试环境---------------')
		//#ifdef H5
		const ipAddress = window.location.href
		const urlObject = new URL(ipAddress)
		const baseUrl = urlObject.origin + urlObject.port
		requestUrl = `http://192.168.101.132:${urlObject.port}`+'/api'+url;
		//#endif
		//#ifdef APP-PLUS
		requestUrl = url_configYz+url;
		//#endif
	}else{
		requestUrl=url_configYz+url
	}
	
	return uni.request({
		url: requestUrl,
		method: 'post',
		data: data,
		dataType: 'json',
		header: {
			'csrfToken':uni.getStorageSync("csrf-token"),
		}
	}).then(res => {
		return res[1]
	}).catch(parmas => {

	})
}
requestYz.get2 = (url, data, power) => {
	return uni.request({
		url: url_configYz + url,
		method: 'get',
		data: data,
		dataType: 'json',
		header:{
			'csrfToken':uni.getStorageSync("csrf-token"),
		}
	}).then(res => {
		return res[1]
	}).catch(parmas => {

	})
}
export default requestYz
